package com.java.basis.thread.cas.atomic;

import sun.misc.Unsafe;

import java.lang.reflect.Field;

/**
 * @author wangning
 * @create 2022-01-29 15:44
 */
public class UnsafeAccessor {
	private static final Unsafe unsafe;
	static {
		try {
			Field theUnsafe = Unsafe.class.getDeclaredField("theUnsafe");
			theUnsafe.setAccessible(true);
			unsafe = (Unsafe) theUnsafe.get(null);
		} catch (Exception e) {
			throw new Error(e);
		}
	}

	public static Unsafe getUnsafe() {
		return unsafe;
	}
}
